package com.shop.util;

import java.util.List;

public class Page<T> {

	private int pageSize;
	private int pageNum;
	private int offSet;
	private Long totalPages;
	private Long totalCount;
	private List<T> result;
	
	public Page(int pageSize,Long totalCount,int pageNum) {
		this.setPageSize(pageSize);
		this.setTotalCount(totalCount);
		this.setPageNum(pageNum);
	}
	
	/**
	 * ��ȡÿҳ��ʾ�������
	 * @return
	 */
	public int getPageSize() {
		return pageSize;
	}
	/**
	 * ����ÿҳ��ʾ�������
	 * @param pageSize
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	/**
	 * ��ȡ��ǰҳ��
	 * @return
	 */
	public int getPageNum() {
		return pageNum;
	}
	/**
	 * ���õ�ǰҳ��
	 * @param pageNum
	 */
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
		if(pageNum < 1) {
			this.pageNum = 1;
		} else if(pageNum > getTotalPages()) {
			this.pageNum = getTotalPages().intValue();
		}
		//��ݵ�ǰҳ���Զ�������ʼ�к�
		setOffSet((this.pageNum - 1) * getPageSize());
	}
	/**
	 * ��ȡ��ʼ�к�
	 * @return
	 */
	public int getOffSet() {
		return offSet;
	}
	/**
	 * ������ʼ�к�
	 * @param offSet
	 */
	public void setOffSet(int offSet) {
		this.offSet = offSet;
	}
	/**
	 * ��ȡ��ҳ��
	 * @return
	 */
	public Long getTotalPages() {
		return totalPages;
	}
	/**
	 * ������ҳ��
	 * @param totalPages
	 */
	private void setTotalPages(Long totalPages) {
		this.totalPages = totalPages;
	}
	/**
	 * ��ȡ�ܼ�¼��
	 * @return
	 */
	public Long getTotalCount() {
		return totalCount;
	}
	/**
	 * �����ܼ�¼��
	 * @param totalCount
	 */
	public void setTotalCount(Long totalCount) {
		this.totalCount = totalCount;
		//����ܼ�¼���Զ�������ҳ��
		Long result = totalCount / getPageSize();
		if(totalCount % pageSize != 0) {
			result += 1;
		}
		setTotalPages(result);
	}
	/**
	 * ��ȡ��ǰҳ����ݼ�
	 * @return
	 */
	public List<T> getResult() {
		return result;
	}
	/**
	 * ���õ�ǰҳ����ݼ�
	 * @param result
	 */
	public void setResult(List<T> result) {
		this.result = result;
	}
	
	
	
}
